package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark93Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark93 extends BaseMark {

    LayoutWatermark93Binding binding;

    public Mark93(@NonNull Context context) {
        super(context);
    }

    public Mark93(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark93(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark93Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
        } else {
            binding = LayoutWatermark93Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "time93", binding.binding1);
        setTime(binding.binding4, new SimpleDateFormat("yyyy年MM月dd日"));
        setWeek(binding.binding3);
        setTime(binding.binding2, new SimpleDateFormat("HH:mm"));

        setText(binding.binding6, "weather93", binding.binding5);
        setText(binding.binding8, "air93", binding.binding7);
        setText(binding.binding10, "height93", binding.binding9);
        setText(binding.binding12, "jingwei93", binding.binding11);
        setText(binding.binding14, "didian93", binding.binding13);

        setText(binding.binding16, "pmL93", binding.binding15);
        setText(binding.binding17, "pmV93", binding.binding15);

        setText(binding.binding19, "soL93", binding.binding18);
        setText(binding.binding20, "soV93", binding.binding18);

        setText(binding.binding22, "pm10L93", binding.binding21);
        setText(binding.binding23, "pm10V93", binding.binding21);

        setText(binding.binding25, "noL93", binding.binding24);
        setText(binding.binding26, "noV93", binding.binding24);

        setText(binding.binding28, "coL93", binding.binding27);
        setText(binding.binding29, "coV93", binding.binding27);

        setText(binding.binding31, "oL93", binding.binding30);
        setText(binding.binding32, "oV93", binding.binding30);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time93", "时间"));
        list.add(new EditItem("weather93", "天气"));
        list.add(new EditItem("air93", "空气质量"));
        list.add(new EditItem("height93", "海拔"));
        list.add(new EditItem("jingwei93", "经纬度"));
        list.add(new EditItem("didian93", "地点"));

        list.add(new EditItem("pmL93", "PM2.5质量"));
        list.add(new EditItem("pmV93", "PM2.5值"));

        list.add(new EditItem("soL93", "SO2质量"));
        list.add(new EditItem("soV93", "SO2值"));

        list.add(new EditItem("pm10L93", "PM10质量"));
        list.add(new EditItem("pm10V93", "PM10值"));

        list.add(new EditItem("noL93", "NO2质量"));
        list.add(new EditItem("noV93", "NO2值"));

        list.add(new EditItem("coL93", "CO质量"));
        list.add(new EditItem("coV93", "CO值"));

        list.add(new EditItem("oL93", "O3质量"));
        list.add(new EditItem("oV93", "O3值"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding4, new SimpleDateFormat("yyyy年MM月dd日"));
            setWeek(binding.binding3);
            setTime(binding.binding2, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
